package xiaohu.day6.HJ65;

import java.util.Scanner;

public class Main2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String a = in.nextLine();
        String b = in.nextLine();
        if(a.length() > b.length()){
            String temp = a;
            a = b;
            b = temp;
        } // make sure a is the shorter string


        int n = a.length(); // n <= m
        int m = b.length();
        int[][] lccs = new int[n][m];
        for (int i = 0; i < n; i++) {
            lccs[i][0] = a.charAt(i) == b.charAt(0) ? 1 : 0;
        }
        for (int i = 0; i < m; i++) {
            lccs[0][i] = a.charAt(0) == b.charAt(i) ? 1 : 0;
        }
        for (int i = 1; i < n; i++) {
            for (int j = 1; j < m; j++){
                if(a.charAt(i) == b.charAt(j)){
                    lccs[i][j] = lccs[i-1][j-1] + 1;
                } else {
                    lccs[i][j] = 0;
                }
            }
        }
        int max = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                max = Math.max(max, lccs[i][j]);
            }
        }
        // get the lccs earlist appear
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++){
                if(lccs[i][j] == max){
                    System.out.println(a.substring(i - max + 1, i + 1));
                    return;
                }
            }
        }
    }
}